//*********************************************************************
//		Copyright (c) 2003 - 2008 Microsoft Corporation.
//      This code is provided under Microsoft Public License, which can be found at
//      http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx 
//
// @File: RepView.cs
//
// Purpose: Repository/View Dialog
//
//
//
// Notes: 
//
//
//	
// History: 
//     @Version: V2.1
//
//     08/18/08 PGV 2.1.001.0 Starting V2.1 (based on 2.0.030.0 code)
//
// @EndHeader@
//*********************************************************************

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace H2V2.ConfigUtility
{
	/// <summary>
	/// Summary description for RepView.
	/// </summary>
	
	public class RepView : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox lbConfig;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		DbInstaller m_dbi;
		private System.Windows.Forms.Button btCancel;
		ArrayList config_array;
		private System.Windows.Forms.Button btWatson;
		bool m_watson;

		public RepView(ref DbInstaller a_dbi)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_dbi = a_dbi;
			config_array = new ArrayList (8);

			GetData ();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lbConfig = new System.Windows.Forms.ListBox();
			this.btCancel = new System.Windows.Forms.Button();
			this.btWatson = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lbConfig
			// 
			this.lbConfig.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.lbConfig.HorizontalScrollbar = true;
			this.lbConfig.ItemHeight = 15;
			this.lbConfig.Location = new System.Drawing.Point(16, 24);
			this.lbConfig.Name = "lbConfig";
			this.lbConfig.Size = new System.Drawing.Size(384, 244);
			this.lbConfig.TabIndex = 0;
			// 
			// btCancel
			// 
			this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btCancel.Location = new System.Drawing.Point(48, 312);
			this.btCancel.Name = "btCancel";
			this.btCancel.Size = new System.Drawing.Size(136, 23);
			this.btCancel.TabIndex = 12;
			this.btCancel.Text = "Close";
			// 
			// btWatson
			// 
			this.btWatson.Location = new System.Drawing.Point(224, 312);
			this.btWatson.Name = "btWatson";
			this.btWatson.Size = new System.Drawing.Size(136, 23);
			this.btWatson.TabIndex = 13;
			this.btWatson.Visible = false;
			this.btWatson.Click += new System.EventHandler(this.btWatson_Click);
			// 
			// RepView
			// 
			this.AcceptButton = this.btCancel;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btCancel;
			this.ClientSize = new System.Drawing.Size(424, 358);
			this.Controls.Add(this.btWatson);
			this.Controls.Add(this.btCancel);
			this.Controls.Add(this.lbConfig);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "RepView";
			this.Text = "View Repository";
			this.ResumeLayout(false);

		}
		#endregion

		void GetData ()
		{
			config_array.Clear ();

			m_dbi.GetConfig (ref config_array, out m_watson);

			lbConfig.Items.Clear ();
			foreach (string s in config_array)
			{
				lbConfig.Items.Add (s);
			}

			if (m_watson)
			{
				btWatson.Text = "Disable Data Export";
				btWatson.Visible = true;
			}
			else
			{
				btWatson.Text = "Enable Data Export";
				btWatson.Visible = true;
			}
		}

		private void btWatson_Click(object sender, System.EventArgs e)
		{
			if (m_watson)
			{
				m_dbi.SetWatson (0);
			}
			else
			{
				m_dbi.SetWatson (1);
			}

			GetData ();
		}

	}
}
